#ifndef __ROOT_REQUESTHANDLERFACTORY__H
#define __ROOT_REQUESTHANDLERFACTORY__H

#include <Poco/NotificationCenter.h>
#include <Poco/Net/HTTPRequestHandlerFactory.h>
#include <Poco/AutoPtr.h>
#include <Poco/Util/AbstractConfiguration.h>
#include <Poco/DynamicFactory.h>

namespace Network{
class CRootRequestHandlerFactory
	:public Poco::Net::HTTPRequestHandlerFactory
{
public:
	CRootRequestHandlerFactory(void);
	virtual ~CRootRequestHandlerFactory(void);
public:
	virtual Poco::Net::HTTPRequestHandler* createRequestHandler(const Poco::Net::HTTPServerRequest& request);

	void Setup(Poco::AutoPtr<Poco::Util::AbstractConfiguration> aConfiguration);
public:
	void addObserver(const Poco::AbstractObserver& aObserver){iRequestCenter.addObserver(aObserver);}
	void removeObserver(const Poco::AbstractObserver& aObserver){iRequestCenter.removeObserver(aObserver);}

protected:
	template <class THandler>
	THandler* CheckURIAndCreateHandler(const std::string& aURI, const std::string& aTemplateURI);
protected:
	Poco::Net::HTTPRequestHandler* CreateRequestFromURI(const std::string& aURI , const std::string& aTemplateURI , const std::string& aClassName);
protected:
	
	Poco::NotificationCenter iRequestCenter;
	Poco::DynamicFactory<Poco::Net::HTTPRequestHandler> iRequestDynFactory;
	std::map<std::string , std::string>		iURITemplateList;
};

}
#endif